#import "BuildingCollection.h"

static BuildingCollection* sharedBuildingCollection = nil; // Shared building collection reference

/**
 * Encapsulates a building collection and provides
 * all the usefull methods derived from PersistentDataCollection.
 * 
 * @author      Justin Hollander
 * @author      James Lin
 * @version     0.7.0
 * @since       0.1.0
 * @see         PersistentDataCollection
 */
@implementation BuildingCollection

/**
 * Get a handle to the shared building collection.
 *
 * @return  the shared building collection
 */
+(BuildingCollection*) sharedBuildingCollection
{
	@synchronized(self) {
		if (sharedBuildingCollection == nil) {
			sharedBuildingCollection = [[super alloc] initWithFile:@"buildingstore.dat" usingSubdirectory:@"BuildingData"];
		}
		return sharedBuildingCollection;
	}
}

/**
 * Retrieve the unique key used for archiving.
 *
 * @return  the key used for keyed archiving
 */
- (NSString*)getArchiveKey {
	@synchronized(self) {
		return @"1dsjdfjr54kwk3";
	}
}

/**
 * Get a sorted list of the buildings.
 *
 * @return  a sorted list of the buildings
 */
- (NSArray*)getSortedBuildings {
	 return [[self getDataTypes] sortedArrayUsingSelector:@selector(compare:)];
}

/**
 * Deallocate the building collection.
 */
-(void) dealloc{
	[sharedBuildingCollection release];
	[super dealloc];
}
@end
